package com.wf.day_0608.test4;

import java.util.*;

/**
 * @author mpk
 * @since 2024/6/9 09:37:19
 */
public class DrawBox implements Runnable {


    int[] arr = {10, 5, 20, 100, 200, 500, 800, 2, 80, 300, 700};


    HashSet<Integer> hashSet = new HashSet<Integer>();

    static int count = 0;


    @Override
    public void run() {

        while (true) {
            synchronized (arr) {
                if (count == 11) {
                    break;
                }

                Random random = new Random();
                int i = random.nextInt(11);
                while (!hashSet.add(i)) {

                    i = random.nextInt(11);
                }

                System.out.println(Thread.currentThread().getName() + "又产生了一个" + arr[i] + "元大奖");
                count++;

            }
            try {
                Thread.sleep(10);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }

        }


    }
}
